package com.sian.datasource;

import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Struct;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;

public class C1Connection implements Connection {
	
	protected Connection passthru;
	protected C1Factory  factory;
	
	public C1Connection(Connection conn){
		 this.passthru = conn;
	}
	
    public C1Connection(C1Factory factory, Connection conn) throws SQLException {
		        	
            	this.factory = factory;
		        this.passthru = conn;
     }

	
	public void clearWarnings() throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.clearWarnings();
	}

	
	public void close() throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.close();
	}

	
	public void commit() throws SQLException {
		// TODO Auto-generated method stub
	   this.passthru.commit();	
	}

	
	public Array createArrayOf(String typeName, Object[] elements)
			throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.createArrayOf(typeName, elements);
	}

	
	public Blob createBlob() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.createBlob();
	}

	
	public Clob createClob() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.createClob();
	}

	
	public NClob createNClob() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.createNClob();
	}

	
	public SQLXML createSQLXML() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.createSQLXML();
	}

	
	public Statement createStatement() throws SQLException {
		// TODO Auto-generated method stub
		return this.factory.getStatement(passthru.createStatement(), this);
	}

	
	public Statement createStatement(int resultSetType, int resultSetConcurrency)
			throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.createStatement(resultSetType, resultSetConcurrency);
	}

	
	public Statement createStatement(int resultSetType,
			int resultSetConcurrency, int resultSetHoldability)
			throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
	}

	
	public Struct createStruct(String typeName, Object[] attributes)
			throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.createStruct(typeName, attributes);
	}

	
	public boolean getAutoCommit() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getAutoCommit();
	}

	
	public String getCatalog() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getCatalog();
	}

	
	public Properties getClientInfo() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getClientInfo();
	}

	
	public String getClientInfo(String name) throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getClientInfo(name);
	}

	
	public int getHoldability() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getHoldability();
	}

	
	public DatabaseMetaData getMetaData() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getMetaData();
	}

	
	public int getTransactionIsolation() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getTransactionIsolation();
	}

	
	public Map<String, Class<?>> getTypeMap() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getTypeMap();
	}

	
	public SQLWarning getWarnings() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.getWarnings();
	}

	
	public boolean isClosed() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.isClosed();
	}

	
	public boolean isReadOnly() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.isReadOnly();
	}

	
	public boolean isValid(int timeout) throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.isValid(timeout);
	}

	
	public String nativeSQL(String sql) throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.nativeSQL(sql);
	}

	
	public CallableStatement prepareCall(String sql) throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.prepareCall(sql);
	}

	
	public CallableStatement prepareCall(String sql, int resultSetType,
			int resultSetConcurrency) throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.prepareCall(sql, resultSetType, resultSetConcurrency);
	}

	
	public CallableStatement prepareCall(String sql, int resultSetType,
			int resultSetConcurrency, int resultSetHoldability)
			throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
	}
    
	
	//***********************************start:prepareStatement method**********************************************
	
	public PreparedStatement prepareStatement(String sql) throws SQLException {
		// TODO Auto-generated method stub
		// System.out.println("======================connection prepareStatement(sql) ="+sql+"=============================");
		return this.factory.getPreparedStatement(passthru.prepareStatement(sql), this, sql);
	}

	
	public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
			throws SQLException {
		// TODO Auto-generated method stub
		System.out.println("======================connection(sql,autoGeneratedKeys)="+sql+"=============================");
		return this.factory.getPreparedStatement(passthru.prepareStatement(sql,autoGeneratedKeys), this, sql);
	}

	
	public PreparedStatement prepareStatement(String sql, int[] columnIndexes)
			throws SQLException {
		// TODO Auto-generated method stub
		return this.factory.getPreparedStatement(passthru.prepareStatement(sql,columnIndexes), this, sql);
	}

	
	public PreparedStatement prepareStatement(String sql, String[] columnNames)
			throws SQLException {
		// TODO Auto-generated method stub
		return this.factory.getPreparedStatement(passthru.prepareStatement(sql,columnNames), this, sql);
	}

	
	public PreparedStatement prepareStatement(String sql, int resultSetType,
			int resultSetConcurrency) throws SQLException {
		// TODO Auto-generated method stub
		return this.factory.getPreparedStatement(passthru.prepareStatement(sql,resultSetType,resultSetType), this, sql);
	}

	
	public PreparedStatement prepareStatement(String sql, int resultSetType,
			int resultSetConcurrency, int resultSetHoldability)
			throws SQLException {
		// TODO Auto-generated method stub
		return this.factory.getPreparedStatement(passthru.prepareStatement(sql,resultSetType,resultSetConcurrency,resultSetHoldability), this, sql);
	}
	//***********************************end:prepareStatement method**********************************************

	
	public void releaseSavepoint(Savepoint savepoint) throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.releaseSavepoint(savepoint);
	}

	
	public void rollback() throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.rollback();
	}

	
	public void rollback(Savepoint savepoint) throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.rollback(savepoint);
	}

	
	public void setAutoCommit(boolean autoCommit) throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.setAutoCommit(autoCommit);
	}

	
	public void setCatalog(String catalog) throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.setCatalog(catalog);
	}

	
	public void setClientInfo(Properties properties)
			throws SQLClientInfoException {
		// TODO Auto-generated method stub
		this.passthru.setClientInfo(properties);
	}

	
	public void setClientInfo(String name, String value)
			throws SQLClientInfoException {
		// TODO Auto-generated method stub
		this.passthru.setClientInfo(name, value);
	}

	
	public void setHoldability(int holdability) throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.setHoldability(holdability);
	}

	
	public void setReadOnly(boolean readOnly) throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.setReadOnly(readOnly);
	}

	
	public Savepoint setSavepoint() throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.setSavepoint();
	}

	
	public Savepoint setSavepoint(String name) throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.setSavepoint(name);
	}

	
	public void setTransactionIsolation(int level) throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.setTransactionIsolation(level);
	}

	
	public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
		// TODO Auto-generated method stub
		this.passthru.setTypeMap(map);
	}

	
	public boolean isWrapperFor(Class<?> iface) throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.isWrapperFor(iface);
	}

	
	public <T> T unwrap(Class<T> iface) throws SQLException {
		// TODO Auto-generated method stub
		return this.passthru.unwrap(iface);
	}

	public void setSchema(String schema) throws SQLException {
		// TODO Auto-generated method stub
		
	}

	public String getSchema() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public void abort(Executor executor) throws SQLException {
		// TODO Auto-generated method stub
		
	}

	public void setNetworkTimeout(Executor executor, int milliseconds)
			throws SQLException {
		// TODO Auto-generated method stub
		
	}

	public int getNetworkTimeout() throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}


}
